package com.qfjy.homework.songyangyang;

import java.util.ArrayList;
import java.util.List;

/**
 * @author:宋阳阳
 * @date:2022/6/29 20:34
 * @version:1.0
 * 组合模式步骤一 创建员工表实体类 带有employee对象的列表
 */
public class Employee {

    // 员工姓名
    private String name;
    // 员工部门
    private String dept;
    // 员工工资
    private int salary;
    // 员工部下 属下
    private List<Employee> subordinates;

    public Employee(String name, String dept, int salary) {
        this.name = name;
        this.dept = dept;
        this.salary = salary;
        subordinates = new ArrayList<Employee>();
    }

    /**
     * 定义操作员工方法
     */
    // 添加下属
    public void add(Employee e) {
        subordinates.add(e);
    }

    // 移除下属
    public void remove(Employee e) {
        subordinates.remove(e);
    }

    public List<Employee> getSubordinates(){
        return subordinates;
    }

    public Employee() {
    }

    public Employee(String name, String dept, int salary, List<Employee> subordinates) {
        this.name = name;
        this.dept = dept;
        this.salary = salary;
        this.subordinates = subordinates;
    }



    @Override
    public String toString() {
        return "Employee{" +
                "name='" + name + '\'' +
                ", dept='" + dept + '\'' +
                ", salary=" + salary +
                '}';
    }
}
